/** @format */

export const useMouse = () => {
    const state = reactive({x: 0, y: 0});
    const update = (e: MouseEvent) => {
        state.x = e.pageX;
        state.y = e.pageY;
    };

    const startListening = () => {
        window.addEventListener('mousemove', update);
    };
    const stopListening = () => {
        window.removeEventListener('mousemove', update);
    };

    onUnmounted(() => {
        window.removeEventListener('mousemove', update);
    });

    return {
        ...toRefs(state),
        stopListening,
        startListening,
    };
};
